import { useAuthed } from '~/composables/useAuthed';
import type { RN } from '~/modules/router';

export function useLoginJudgment() {
  const authed = useAuthed();
  const router = useRouter();

  // 打开弹窗
  function openModal(callback: () => void) {
    // if (authed.value) {
    //   callback();
    // }
    // else {
    //   globalPopups.sign.open?.({ view: 'signIn' });
    // }
    callback();
  }

  // 打開地址
  function openRoute(name?: RN, query?: any) {
    if (authed.value) {
      router.push({ name, query: { ...query } });
    }
    else {
      globalPopups.sign.open?.({ view: 'signIn' });
    }
  }

  return {
    openModal,
    openRoute,
  };
};
